--[[/**
-- * 
 * 阿莉克希亚
 * 触发时让范围内的敌人击退
-- *
-- */]]

---@class BuffEffect395100 : BaseBuffEffect
BuffEffect395100 = ClientFight.CreateClass("BuffEffect395100", ClientFight.BaseBuffEffect)
local t = BuffEffect395100
t.BUFF_EFFECT_395100_ACTION_FRAME = "BUFF_EFFECT_395100_ACTION_FRAME";
---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local fighter = buff.target;
    local fightTeam = fight.teams[3 - fighter.teamIndex];
    local effectValues = buff.buffBean.f_BuffEffectValue;

    local lastActionFrame = buff.effectParams[t.BUFF_EFFECT_395100_ACTION_FRAME] or 0;
    local nowFrame = fight.frame;
    local diffFrame = nowFrame - lastActionFrame;
    if (lastActionFrame > 0 and diffFrame < effectValues[1] / Global.FIGHT_FRAME) then
        return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
    end

    local shape = Rectangle2.New(effectValues[2], effectValues[3]);
    local peopleAmount = 0;
    local targets = {};
    for k, f in pairs(fightTeam.fighters) do
        if (f:isSummons() and not f.isRealSummons()) then
            goto continue;
        end
        if (f:isDie()) then
            goto continue;
        end
        if (not DistanceUtil.overlap(fighter.position, shape, f.position, f.shape)) then
            goto continue;
        end
        --buffManager.addBuff(fight,buff.getSkill(),buff.getSource(),f,false, effectValues[3],1);
        table.insert(targets, f);
        peopleAmount = peopleAmount + 1;
        :: continue ::
    end
    for k, f in pairs(targets) do
        ClientFight.BaseBuffEffect.triggerSkill(self, fight, fighter, f, effectValues[4]);
    end
    if (peopleAmount > 0) then
        local logPeopleAmount = peopleAmount;
        buff.effectParams[t.BUFF_EFFECT_395100_ACTION_FRAME] = nowFrame;
        SkillRoleMgr.savePathFile(string.format("[%s][EFFECT]Fighter %s  Buff%s 范围内有敌人%s人，触发击退",
                fight.frame, buff.target.fighterId, buff.modelId, logPeopleAmount
        ));
    end

    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

t.New()